package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.app.util.FreemarkerUtil;
import cn.wolfcode.trip.base.domain.Cart;
import cn.wolfcode.trip.base.domain.Goods;
import cn.wolfcode.trip.base.domain.GoodsType;
import cn.wolfcode.trip.base.domain.PointMsg;
import cn.wolfcode.trip.base.query.CartQueryObject;
import cn.wolfcode.trip.base.query.GoodsQueryObject;
import cn.wolfcode.trip.base.service.ICartService;
import cn.wolfcode.trip.base.service.IGoodsService;
import cn.wolfcode.trip.base.service.IGoodsTypeService;
import cn.wolfcode.trip.base.service.IPointMsgService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/carts")
public class CartController {

    @Autowired
    private ICartService cartService;

    /*
        新增一条购物车信息
        资源: /carts
        动作: POST
        参数: userId=xx&goodsId=xx
     */
    @PostMapping
    public void saveOrUpdate(CartQueryObject qo) {
        cartService.saveOrUpdate(qo);
    }

    /*
        删除指定id的购物车信息
        资源:/carts/{id}
        动作: DELETE
        参数:
     */
    @DeleteMapping("/{id}")
    public void delete(@PathVariable Long id){
        cartService.delete(id);
    }

    /*
        成功兑换修改指定购物车信息的状态,并添加结算时间
        资源: /carts/{id}
        动作: PUT
        参数: state=1
     */
    // ok
    @PutMapping("/{id}")
    public void updateState(Cart cart){
        cartService.updateState(cart);
    }

    /*
        新增一条购物信息
        资源: /carts/pointmsgs
        动作: POST
        参数: PointMsg=xxx
     */
    @PostMapping("/pointmsgs")
    public void savePointMsg(PointMsg pointMsg){
        cartService.savePointMsg(pointMsg);
    }

    /*
        更新指定购物信息的物品数量
        资源: /carts/{id}/counts
        动作: PUT
        参数: param=xx
     */
    @PutMapping("/{id}/counts")
    public void updateCounts(Cart cart){
        cartService.updateCount(cart);
    }
    /*
        获取指定的购物车信息
        资源: /carts/{id}
        动作: GET
        参数
     */
    @GetMapping("/{id}")
    public Object getCart(@PathVariable Long id){
        return cartService.getCart(id);
    }

}
